package com.zqh.apishoppingcartquery.controller;

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zqh.apishoppingcartquery.redis.RedisUtil;
import com.zqh.myfmmall.clients.ShoppingCartQueryClient;
import com.zqh.myfmmall.result.Result;
import com.zqh.myfmmall.rowbeans.vo.ShoppingCartVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Description :
 * @Author :kono淇杭哒、
 * @Create 2022-03-05 23:00
 */
@RestController
@RequestMapping("shoppingCart/query")

public class ApiShoppingCartQueryController{
    /**
     * 服务对象
     */
    @Autowired
    private ShoppingCartQueryClient shoppingCartQueryClient;
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private RedisUtil redisUtil;

    @GetMapping("listVo")
    public Result listVoByUserId(){
        ObjectMapper objectMapper = new ObjectMapper();
        String token = request.getHeader("token");
        String userId = (String) redisUtil.get(token);
        Result result = shoppingCartQueryClient.listVoByUserId(userId);
        return result;
    }

    @GetMapping("listVoByIds")
    public Result listVoByIds(@RequestParam("ids") List<String> ids){
        ObjectMapper objectMapper = new ObjectMapper();
        Result result = shoppingCartQueryClient.listByIds(ids);
        return result;
    }
}
